home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Oberon⁄F™ 1.1 / Obx / Docu / Caps (.txt) < prev    next >
Encoding:
Oberon Document  |  1996-01-05  |  4.2 KB  |  71 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. Helvetica
  17. Helvetica
  18. Helvetica
  19. Helvetica
  20. MODULE ObxCaps;
  21.     IMPORT Domains, Models, TextModels, TextControllers;
  22.     PROCEDURE Do*;
  23.         VAR c: TextControllers.Controller; beg, end: LONGINT;
  24.             r: TextModels.Reader; ch: CHAR;
  25.             buf: TextModels.Model; w: TextModels.Writer; script: Domains.Operation;
  26.     BEGIN
  27.         c := TextControllers.Focus();
  28.         IF (c # NIL) & c.HasSelection() THEN
  29.             c.GetSelection(beg, end);
  30.             (* upper case text will be copied into this buffer *)
  31.             buf := TextModels.Clone(c.text); w := buf.NewWriter(NIL);
  32.             r := c.text.NewReader(NIL); r.SetPos(beg);
  33.             r.ReadChar(ch);
  34.             WHILE (r.Pos() <= end) & ~r.eot DO
  35.                 IF (ch >= "a") & (ch <= "z") THEN ch := CAP(ch) END;
  36.                 w.WriteChar(ch);
  37.                 r.ReadChar(ch)
  38.             END;
  39.             Models.BeginScript(c.text, "Caps", script);
  40.             c.text.Delete(beg, end); c.text.CopyFrom(beg, buf, 0, end - beg);
  41.             Models.EndScript(c.text, script)
  42.         END
  43.     END Do;
  44. END ObxCaps.
  45. TextControllers.StdCtrlDesc
  46. TextControllers.ControllerDesc
  47. Containers.ControllerDesc
  48. Controllers.ControllerDesc
  49. TextRulers.StdRulerDesc
  50. TextRulers.RulerDesc
  51. TextRulers.StdStyleDesc
  52. TextRulers.StyleDesc
  53. TextRulers.AttributesDesc
  54. Helvetica
  55. DevCommanders.StdViewDesc
  56. DevCommanders.ViewDesc
  57. Helvetica
  58. Oberon by Example: ObxCaps
  59. This example shows how the built-in text subsystem of Oberon/F can be extended by new commands. To demonstrate this possibility, a command is shown which fetches the selection in the focus view (assuming the focus view is a text view), creates a new empty text, copies the selection into this new text (but with all small letters turned into capital letters), and then replaces the selection by the newly created text. In short, this command turns the selected text stretch into all capital letters.
  60. As an example, select the test string several lines below, and then click on the following commander:
  61.  ObxCaps.Do
  62. teSTstring834 .-st
  63. You'll note that the selection has turned into all caps.
  64. But now comes the surprise: execute Undo
  65. Caps in the Edit menu. As a result, the effect of the uppercase operation is undone! In Oberon/F, most operations are undoable; this also holds for the Delete and CopyFrom procedures in the above example. Thus, you need to do nothing special in order to render such a command undoable!
  66. However, you may have noticed that there is something special in the sample program: there is a BeginScript / EndScript pair of procedure calls before resp. after the calls to Delete / CopyFrom. They bundle the sequence of a Delete followed by a CopyFrom into one single compound
  67. command, meaning that the user need not undo both of these operations individually, but rather in one single step.
  68. In this example we have seen how an existing displayed text and its selection are accessed, how a buffer text is created, and how the selected text stretch is replaced by the buffer's contents.
  69. Helvetica
  70. Documents.ControllerDesc
  71.